class Solution:
	# @param a list of integers
	# @return an integer
	def removeDuplicates(self, A):
		if len(A) <= 2:
			return len(A)
		i = 0
		for j in xrange(0, len(A)-1):
			if A[j] != A[j+1]:
				if A[j-1] == A[j]:
					A[i] = A[j]
					i += 1
				A[i] = A[j]
				i += 1
		if A[-1] == A[-2]:
			A[i] = A[-1]
			i += 1
		A[i] = A[-1]
		return i+1

if __name__ == '__main__':
	a = [1,1,1,2,2,2,2,3,3]
	so = Solution()
	print(a[:so.removeDuplicates(a)])

        